<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="供应商工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierWorkNo', validatorRules.supplierWorkNo]" placeholder="请输入供应商工单编号"></a-input>
        </a-form-item>
        <a-form-item label="国网侧供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入国网侧供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商产品厂内编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productModel', validatorRules.productModel]" placeholder="请输入供应商产品厂内编码"></a-input>
        </a-form-item>
        <a-form-item label="生产设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentName', validatorRules.equipmentName]" placeholder="请输入生产设备名称"></a-input>
        </a-form-item>
        <a-form-item label="生产设备唯一识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentUniqueCode', validatorRules.equipmentUniqueCode]" placeholder="请输入生产设备唯一识别号"></a-input>
        </a-form-item>
        <a-form-item label="物资品类类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryType', validatorRules.categoryType]" placeholder="请输入物资品类类型"></a-input>
        </a-form-item>
        <a-form-item label="厂区编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'factoryCode', validatorRules.factoryCode]" placeholder="请输入厂区编号"></a-input>
        </a-form-item>
        <a-form-item label="供应商数据编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierSupportId', validatorRules.supplierSupportId]" placeholder="请输入供应商数据编号"></a-input>
        </a-form-item>
        <a-form-item label="速度（副闸）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'speedDeputy', validatorRules.speedDeputy]" placeholder="请输入速度（副闸）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="速度（合闸）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'speedClose', validatorRules.speedClose]" placeholder="请输入速度（合闸）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="速度（主闸）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'speedMain', validatorRules.speedMain]" placeholder="请输入速度（主闸）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（主闸）_A" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'masteropentimeA', validatorRules.masteropentimeA]" placeholder="请输入时间（主闸）_A" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（主闸）_B" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'masteropentimeB', validatorRules.masteropentimeB]" placeholder="请输入时间（主闸）_B" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（主闸）_C" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'masteropentimeC', validatorRules.masteropentimeC]" placeholder="请输入时间（主闸）_C" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（副闸）_A" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'salveopentimeA', validatorRules.salveopentimeA]" placeholder="请输入时间（副闸）_A" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（副闸）_B" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'salveopentimeB', validatorRules.salveopentimeB]" placeholder="请输入时间（副闸）_B" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（副闸）_C" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'salveopentimeC', validatorRules.salveopentimeC]" placeholder="请输入时间（副闸）_C" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（合闸）_A" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'clonetimeA', validatorRules.clonetimeA]" placeholder="请输入时间（合闸）_A" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（合闸）_B" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'clonetimeB', validatorRules.clonetimeB]" placeholder="请输入时间（合闸）_B" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="时间（合闸）_C" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'clonetimeC', validatorRules.clonetimeC]" placeholder="请输入时间（合闸）_C" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="行程" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'route', validatorRules.route]" placeholder="请输入行程" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="行程图片_A" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'routePictureA', validatorRules.routePictureA]" placeholder="请输入行程图片_A"></a-input>
        </a-form-item>
        <a-form-item label="行程图片_B" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'routePictureB', validatorRules.routePictureB]" placeholder="请输入行程图片_B"></a-input>
        </a-form-item>
        <a-form-item label="行程图片_C" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'routePictureC', validatorRules.routePictureC]" placeholder="请输入行程图片_C"></a-input>
        </a-form-item>
        <a-form-item label="波形数据" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'waveform', validatorRules.waveform]" placeholder="请输入波形数据"></a-input>
        </a-form-item>
        <a-form-item label="采集时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择采集时间" v-decorator="[ 'checkTime', validatorRules.checkTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'pdCode', validatorRules.pdCode]" placeholder="请输入工序"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZpgEipZhdqJxtxModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
          puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
          supplierWorkNo:{rules: [{ required: true, message: '请输入供应商工单编号!' }]},
          supplierCode:{rules: [{ required: true, message: '请输入国网侧供应商编码!' }]},
          productModel:{},
          equipmentName:{},
          equipmentUniqueCode:{},
          categoryType:{rules: [{ required: true, message: '请输入物资品类类型!' }]},
          factoryCode:{},
          supplierSupportId:{},
          speedDeputy:{},
          speedClose:{},
          speedMain:{},
          masteropentimeA:{rules: [{ required: true, message: '请输入时间（主闸）_A!' }]},
          masteropentimeB:{rules: [{ required: true, message: '请输入时间（主闸）_B!' }]},
          masteropentimeC:{rules: [{ required: true, message: '请输入时间（主闸）_C!' }]},
          salveopentimeA:{rules: [{ required: true, message: '请输入时间（副闸）_A!' }]},
          salveopentimeB:{rules: [{ required: true, message: '请输入时间（副闸）_B!' }]},
          salveopentimeC:{rules: [{ required: true, message: '请输入时间（副闸）_C!' }]},
          clonetimeA:{rules: [{ required: true, message: '请输入时间（合闸）_A!' }]},
          clonetimeB:{rules: [{ required: true, message: '请输入时间（合闸）_B!' }]},
          clonetimeC:{rules: [{ required: true, message: '请输入时间（合闸）_C!' }]},
          route:{rules: [{ required: true, message: '请输入行程!' }]},
          routePictureA:{rules: [{ required: true, message: '请输入行程图片_A!' }]},
          routePictureB:{rules: [{ required: true, message: '请输入行程图片_B!' }]},
          routePictureC:{rules: [{ required: true, message: '请输入行程图片_C!' }]},
          waveform:{},
          checkTime:{rules: [{ required: true, message: '请输入采集时间!' }]},
          pdCode:{},
          ioflag:{},
          message:{},
        },
        url: {
          add: "/zpgEipZhdqJxtx/add",
          edit: "/zpgEipZhdqJxtx/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','supplierWorkNo','supplierCode','productModel','equipmentName','equipmentUniqueCode','categoryType','factoryCode','supplierSupportId','speedDeputy','speedClose','speedMain','masteropentimeA','masteropentimeB','masteropentimeC','salveopentimeA','salveopentimeB','salveopentimeC','clonetimeA','clonetimeB','clonetimeC','route','routePictureA','routePictureB','routePictureC','waveform','checkTime','pdCode','ioflag','message'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','supplierworkno','suppliercode','productmodel','equipmentname','equipmentuniquecode','categorytype','factorycode','suppliersupportid','speeddeputy','speedclose','speedmain','masteropentimea','masteropentimeb','masteropentimec','salveopentimea','salveopentimeb','salveopentimec','clonetimea','clonetimeb','clonetimec','route','routepicturea','routepictureb','routepicturec','waveform','checktime','pdCode','ioflag','message','remarkone','remarktwo','remarkthree','remarkfour','remarkfive'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>